$(function() {
	$('#loginForm').bootstrapValidator({
		live : 'disabled',
		feedbackIcons : {
			valid : 'glyphicon glyphicon-ok',
			invalid : 'glyphicon glyphicon-remove',
			validating: 'glyphicon glyphicon-refresh'
		},
		fields : {
			username : {
				validators : {
					notEmpty : {
						message : '账号不能为空.'
					}
				}
			},
			password : {
				validators : {
					notEmpty : {
						message : '密码不能为空.'
					},
					remote: {
						url: ctxPath + '/login.do',
						data: function(validator) {
							return {
								username: validator.getFieldElements('username').val()
							};
						},
						message: '账号或密码错误.'
					}
				}
			}
		},
		submitHandler: function(validator, form, submitButton) {
			location.href = ctxPath + "/initHomePage.do";
		}
	});
	
	$('#loginBtn').click(function() {
		var password = $("#password").val();
		if($.trim(password) != "") {
			$("#password").val($.md5(password));
		}	
		$("#loginForm").submit();
    });
	
	$('#registerBtn').click(function() {
        location.href = ctxPath + "/initRegisterPage.do";
    });
	
	$('#recoveryBtn').click(function() {
        location.href = ctxPath + "/initRecoveryPage.do";
    });
});